iT邦幫忙

0

每日一篇學習筆記 直到我做完專題 :( [Day32]

  • 分享至 

  • xImage
  •  

今天實際來做看看連接資料庫

登入之後保存進資料庫

private void loginSuccess() {
        String desc = String.format("手機號碼:%s通過登入驗證,點擊確定返回驗證頁面",et_phone.getText().toString());
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("驗證成功");
        builder.setMessage(desc);
        builder.setPositiveButton("確認", (dialogInterface, i) -> {
            finish();
        });
        builder.setNegativeButton("驗證其他號碼",null);
        AlertDialog dialog = builder.create();
        dialog.show();

            //保存至數據庫
            Logininfo info =new Logininfo();
            info.phone = et_phone.getText().toString();
            info.password = et_password.getText().toString();
            info.remember = ck_remember.isChecked();
            mHelper.save(info);
    }

開始前先打開讀寫然後reload之前記住的密碼

@Override
    protected void onStart() {
        super.onStart();
        mHelper = LoginDBHelper.getInstance(this);
        mHelper.openReadLink();
        mHelper.openWriteLink();

        reload();
    }

reload

private void reload() {
        Logininfo info = mHelper.queryTop();
        if(info != null&&info.remember){
            et_phone.setText(info.phone);
            et_password.setText(info.password);
            ck_remember.setChecked(true);
        }
    }

還有偵測資料庫內有沒有匹配的電話號碼

@Override
    public void onFocusChange(View view, boolean b) {
        if(view.getId() == R.id.et_password&&b){
            Logininfo info = mHelper.queryByPhone(et_phone.getText().toString());
            if(info!=null){
                et_password.setText(info.password);
                ck_remember.setChecked(info.remember);
            }else{
                et_password.setText("");
                ck_remember.setChecked(false);
            }
        }
    }

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言